A sentinel node is a specifically designated node used with linked lists and trees as a traversal path terminator. A sentinel node does not hold or reference any data managed by the data structure. Sentinels are used as an alternative over using null as the path terminator in order to get one or more of the following benefits:
Below is an example of a sentinel node in a binary tree implementation:[1]
struct jsw_node { int data; int level; struct jsw_node *link[2]; }; struct jsw_node *nil; int jsw_init ( void ) { nil = malloc ( sizeof *nil ); if ( nil == NULL ) return 0; nil->level = 0; nil->link[0] = nil->link[1] = nil; return 1; }
As nodes that would normally link to NULL now link to "nil" (including nil itself), it removes the need for an expensive branch operation to check for NULL. NULL itself is known as a sentinel value, a different approach to the same problem.